<template>
  <ex-dialog
    width="50%"
    class="ex-diolog"
    title="选择定位"
    :visible="visible"
    @closeDialog="handleClose"
  >
    <div>选择定位</div>
    <div id="app"></div>
    <template v-if="data.status == '3'" slot="footer">
      <el-button type="danger" @click="rejectClick">拒绝</el-button>
      <el-button type="primary" @click="agreeClick">同意</el-button>
    </template>
  </ex-dialog>
</template>
<script>
// api
import { getDetail, approved, reject } from "@/api/regitserVerify";

export default {
  props: {
    visible: Boolean,
    id: String,
  },
  data() {
    return {
      types: {
        1: "企业",
        2: "个人",
      },
      status: {
        1: "正常",
        2: "冻结",
      },
      img_url: this.$IMG_URL,
      data: {},
    };
  },
  created() {
    // this.getDetail();
  },
   mounted () {
    this.initMap()
  },
  methods: {
    // 地图初始化函数，本例取名为init，开发者可根据实际情况定义
    initMap() {
      // 定义地图中心点坐标
      var center = new window.TMap.LatLng(39.98412, 116.307484);
      // 定义map变量，调用 TMap.Map() 构造函数创建地图
      var map = new window.TMap.Map(document.getElementById("app"), {
        center: center, // 设置地图中心点坐标
        zoom: 17.2, // 设置地图缩放级别
        pitch: 43.5, // 设置俯仰角
        rotation: 45, // 设置地图旋转角度
      });
      console.log(map);
      console.log(window);
    },
    getDetail() {
      getDetail(this.id).then((res) => {
        console.log("获取详情", res);
        const { result } = res;
        result.merchantTypeText = this.$getStatusText(
          "merchant_type",
          result.merchantType
        );
        result.statusText = this.$getStatusText(
          "account_status",
          result.status
        );
        result.applyStatusText = this.$getStatusText(
          "register_verify_status",
          result.applyStatus
        );

        this.data = result;
      });
    },
    handleClose() {
      this.$emit("update:visible", false);
    },

    handleSuccess(msg) {
      if (msg === "已拒绝") {
        var type = "error";
      } else {
        var type = "success";
      }
      this.$message({
        message: msg,
        type: type,
        duration: 1500,
        onClose: () => {
          this.handleClose();
          this.$emit("success");
        },
      });
    },

    rejectClick() {
      this.$confirm("是否拒绝?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning",
      })
        .then(() => {
          console.log("hgahah");
          reject(this.id).then((res) => {
            this.$message({
              message: "已拒绝【" + this.data.merchantName + "】入住申请",
              type: "error",
              duration: 1500,
            });
            this.$emit("success");
          });
        })
        .catch();
    },

    agreeClick() {
      this.$confirm("是否同意?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning",
      })
        .then(() => {
          approved(this.id).then((res) => {
            this.$message({
              message: "已同意【" + this.data.merchantName + "】入住申请",
              type: "success",
              duration: 1500,
            });
            this.$emit("success");
          });
        })
        .catch();
    },
  },
};
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
  }
  .grid-layout {
    width: 560px;
    margin: 0 auto;
  }
  .img {
    display: block;
    width: 100px;
    height: auto;
  }
  
}
// #app {
//         width: 100%;
//         height: 300px;
//     }
</style>
